package org.xuyuji.web.dao;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.ArrayList;
import java.util.List;

import org.xuyuji.web.dto.Menu;

public class MenuDao {
	public List<Menu> getAllMenu(){
		List<Menu> list = new ArrayList<Menu>();
		try {
			Statement s = ConnFactory.getConn().createStatement();
			ResultSet rs =  s.executeQuery("select menu_id,menu_name,url,parent_id,sort from menu order by parent_id,sort");
			
			while(rs.next()){
				Menu menu = new Menu();
				menu.setMenuId(rs.getInt(1));
				menu.setMenuName(rs.getString(2));
				menu.setUrl(rs.getString(3));
				menu.setParentId(rs.getInt(4));
				menu.setSort(rs.getInt(5));
				list.add(menu);
			}
		} catch (SQLException e) {
			System.out.println(e);
		} catch (ClassNotFoundException e) {
			System.out.println(e);
		}
		
		return list;
	}
	
	public static void main(String[] args) throws Exception {
		MenuDao dao = new MenuDao();
		System.out.println(dao.getAllMenu());
	}
}
